# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        黄周云  
# Name:         test08
# Description:  例11.6
# Author:       ASUS
# Date:         2019/3/25
#-------------------------------------------------------------------------------


import re
s = "a+b+c+"
strList = ["abc","aabc","bbabc","aabbcccxyz"]
for value in strList:
    m = re.match(s,value)
    if m is not None:
        print(m.group())
    else:
        print("{}不匹配{}".format(value,s))

print("-------------------")

#[a-z]是设置字母或关系的简化形式
# s = "\d\d\d-[a-z][a-z][a-z]"
#{3}表示让前面修饰的特殊字符“\d”重复三次
s = "\d{3}-[a-z]{3}"
strList = ["123-abc","1234-xyz","1-xyzabc","543-xyz^%ab"]
for value in strList:
    m = re.match(s,value)
    if m is not None:
        print(m.group())
    else:
        print("{}不匹配{}".format(value,s))

print("-----------------------")

s = "[a-z]?\d+"
strList = ["1234","a123","ab432","b234abc"]
for value in strList:
    m = re.match(s,value)
    if m is not None:
        print(m.group())
    else:
        print("{}不匹配{}".format(value,s))

print("----------------------------")

email = "\w+@(\w+\.)*\w+\.com"
emailList = ["abc@126.com","test@mail.geekori.com","test-abc@geekori.com","abc@geekori.com.cn"]
for value in emailList:
    m = re.match(email,value)
    if m is not None:
        print(m.group())
    else:
        print("{}不匹配{}".format(value,email))
strValue = "我的email是lining@geekori.com，请发邮件到这个邮箱"
#\w对中文也匹配
m = re.search(email,strValue)
print(m)
#规定@前面的部分只能是至少一个字母(大写或小写）和数字，不能是其他字符
email = "[a-zA-Z0-9]+@(\w+\.)*\w+\.com"
m = re.search(email,strValue)
print(m)

